import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {FetchService} from '../../core/net/fetch.service';
import {NzMessageService} from 'ng-zorro-antd';
import {Router} from "@angular/router";

@Component({
  selector: 'app-gooflow-list',
  templateUrl: './gooflow-list.component.html',
  styleUrls: ['./gooflow-list.component.scss']
})
export class GooflowListComponent implements OnInit {
  searchForm: FormGroup;
  tableDataRes = {
    "data": {
      "pageNum": 1,
      "pageSize": 15,
      "size": 3,
      "startRow": 1,
      "endRow": 3,
      "total": 1,
      "pages": 1,
      "list": [
        {
          "flowId": "1",
          "name": "秦汉渠调度流程",
          "version": "1.0",
          "creator": "admin",
          "ctDate": "2018-12-04 10:28:47"
        }
      ],
      "prePage": 0,
      "nextPage": 0,
      "isFirstPage": true,
      "isLastPage": true,
      "hasPreviousPage": false,
      "hasNextPage": false,
      "navigatePages": 8,
      "navigatepageNums": [
        1
      ],
      "navigateFirstPage": 1,
      "navigateLastPage": 1,
      "lastPage": 1,
      "firstPage": 1
    }
  };

  tableData;

  constructor(private fb: FormBuilder,
              private router: Router,
              private fetchService: FetchService,
              private message: NzMessageService) {
    this.searchForm = this.fb.group({
      name: ['']
    });
  }

  ngOnInit(): void {
    this.queryInfo();
  }

  queryInfo(): void {
    const params = {
      name: this.searchForm.value.name
    };
    this.fetchService.post<any>('flow/flowTemp/list', params).subscribe(res => {
      console.log(res);
      this.tableData = res.list;
    });
  }

  openEditModal(data, editType): void {
    this.router.navigate(['/gooflow/detail'],
      {queryParams: {id: data.flowId, version: data.version, editType: editType}});
  }

  clearValue(): void {
    this.searchForm.patchValue({name: ''});
  }

  onDelete(id): void {

  }
}
